package com.gk.panda.apis.patrol.controller.client;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.panda.apis.patrol.servicr.PatrolService;
import com.gk.panda.commons.result.Result;
import com.gk.panda.pojo.patrol.dto.PatrolCountDTO;
import com.gk.panda.pojo.patrol.dto.PatrolListDTO;
import com.gk.panda.pojo.patrol.dto.MyPatrolDTO;
import com.gk.panda.pojo.patrol.dto.UpdateInfoDTO;
import com.gk.panda.pojo.patrol.request.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;


/**
 * @Author：xxz
 * @Create: 2022/11/1 16:25
 */
@RestController
@RequestMapping("/patrol/client")
@Api(tags = "巡护App相关接口")
public class PatrolClientController {

    @Autowired
    private PatrolService patrolService;

    @PostMapping("/create")
    @ApiOperation("创建巡护")
    public Result<?> create(@Validated @RequestBody SavePatrolRequest request){
        return patrolService.create(request);
    }
    @PutMapping("/stop")
    @ApiOperation("停止巡护")
    public Result<?> stop(@Validated @RequestBody StopPatrolRequest request){
        return patrolService.stop(request);
    }

    @GetMapping("/check")
    @ApiOperation("检测当前用户是否有未完成的巡护")
    public Result<?> check(){
        return patrolService.check();
    }


    @GetMapping("/count")
    @ApiOperation("巡护事件数量")
    public Result<PatrolCountDTO> countPatrol(@RequestParam(value = "type",required = false) String type){
        return Result.ok(patrolService.countPatrol(type));
    }
    @GetMapping("/list")
    @ApiOperation("巡逻记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "巡护类型,TRANSECT:样线巡护，DAILY:日常巡护"),
            @ApiImplicitParam(name = "pageNum", value = "分页页数"),
            @ApiImplicitParam(name = "pageNum", value = "分页条数")
    })
    public Result<Page<PatrolListDTO>>PatrolList(PatrolListRequest request ){
        return Result.ok(patrolService.PatrolList(request));
    }
    @GetMapping("/myPatrrol")
    @ApiOperation("巡护记录信息")
    public Result<MyPatrolDTO>myPatrol(){
        return patrolService.myPatrol();

    }

    @PostMapping("/location")
    @ApiOperation("提交位置信息，此接口宜采用定期上报位置信息")
    public Result<?> location(@RequestBody @Validated LocationRequest request){
        patrolService.location(request);
        return Result.ok();
    }

    @PostMapping("/location/batch")
    @ApiOperation("批量提交位置信息")
    public Result<?> BatchLocation(@RequestBody @Valid BatchLocationRequest request){
        return patrolService.BatchLocation(request);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除巡护")
    private Result<?> remove(@NotNull @RequestParam Long id){
        return patrolService.remove(id);
    }
    @GetMapping("/updateInfo")
    @ApiOperation("获取编辑详情")
    public Result<UpdateInfoDTO> updateInfo(@RequestParam("patrolId") Long patrolId){
        return Result.ok(patrolService.updateInfo(patrolId));
    }

    @PutMapping("/update")
    @ApiOperation("修改巡护")
    private Result<?> update(@Validated UpdatePatrolRequest request){
        return patrolService.update(request);
    }
    @GetMapping("/height")
    @ApiOperation("计算巡护结束高差")
    public Result<?> getHeight(@NotNull @RequestParam Long id){
        return Result.ok(patrolService.getHeight(id));
    }
}
